using System;
using System.Collections;
using System.Collections.Generic;
using Brick;

namespace Assets.Scripts.GDK
{
	public class gdk_coroutineAnimators
	{
		public static void playAnimators(List<gdk_coroutineAnimatorStruct> animatorObjList, Action callback)
		{
			play(animatorObjList, callback);
		}

		public static void playAnimators(List<gdk_coroutineAnimatorStruct> animatorObjList)
		{
			play(animatorObjList, delegate
			{
			});
		}

		private static void play(List<gdk_coroutineAnimatorStruct> animatorObjList, Action callback)
		{
			float num = 0f;
			for (int i = 0; i < animatorObjList.Count; i++)
			{
				gdk_coroutineAnimatorStruct gdk_coroutineAnimatorStruct = animatorObjList[i];
				if (!gdk_coroutineAnimatorStruct.async)
				{
					num = (gdk_coroutineAnimatorStruct.await = num + gdk_coroutineAnimatorStruct.await);
				}
				gdk_coroutine.Instance.StartCoroutine(demoAnimatorFun(gdk_coroutineAnimatorStruct, gdk_coroutineAnimatorStruct.await, delegate
				{
					if (checkAllAnimatorComplete(animatorObjList))
					{
						callback();
					}
				}));
			}
		}

		private static bool checkAllAnimatorComplete(List<gdk_coroutineAnimatorStruct> animatorObjList)
		{
			for (int i = 0; i < animatorObjList.Count; i++)
			{
				gdk_coroutineAnimatorStruct gdk_coroutineAnimatorStruct = animatorObjList[i];
				if (!gdk_coroutineAnimatorStruct.isComplete)
				{
					return false;
				}
			}
			return true;
		}

		private static IEnumerator demoAnimatorFun(gdk_coroutineAnimatorStruct animatorObj, float beforeWait, Action completeCallback)
		{
			yield return new gdk_waitForSeconds(beforeWait);
			animatorObj.action(delegate
			{
				animatorObj.isComplete = true;
				completeCallback();
			});
		}
	}
}
